function countMinCarNum(cars) {
  let carsStr = cars.join(',')
  carsStr = carsStr.replaceAll('1,1,1', 'b').replaceAll('1,1', 'm').replaceAll('1', 's').replaceAll('0', '').replaceAll(',', '')
  return carsStr.length
}

console.log(countMinCarNum([1,1,0,0,1,1,1,0,1]));